package com.eurasia.assignment.job;

import com.eurasia.assignment.service.HOJAuthTokenService;
import com.eurasia.assignment.service.port.out.HOJAuthToken;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@RequiredArgsConstructor
public class RefreshHOJToken {

    private final HOJAuthTokenService hojAuthTokenService;

    @Scheduled(initialDelay = 0, fixedRate = 7200000) // 启动后立即执行，之后每2小时（7200000ms）执行一次
    public void executeTask() {
        HOJAuthToken hojAuthToken = hojAuthTokenService.refreshHOJAuthToken();
        System.out.println("hojAuthToken" + hojAuthToken);
        System.out.println("Task executed at: " + new Date());
    }
}
